home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / tools / indent.lha / indent / globals.h < prev    next >
C/C++ Source or Header  |  1992-07-06  |  15KB  |  310 lines

  1. /*
  2.  * Copyright 1989 Object Design, Inc.
  3.  * Copyright (c) 1985 Sun Microsystems, Inc.
  4.  * Copyright (c) 1980 The Regents of the University of California.
  5.  * Copyright (c) 1976 Board of Trustees of the University of Illinois.
  6.  * All rights reserved.
  7.  *
  8.  * Redistribution and use in source and binary forms are permitted
  9.  * provided that the above copyright notice and this paragraph are
  10.  * duplicated in all such forms and that any documentation,
  11.  * advertising materials, and other materials related to such
  12.  * distribution and use acknowledge that the software was developed
  13.  * by the University of California, Berkeley, the University of Illinois,
  14.  * Urbana, and Sun Microsystems, Inc.  The name of either University
  15.  * or Sun Microsystems may not be used to endorse or promote products
  16.  * derived from this software without specific prior written permission.
  17.  * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
  18.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  19.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  20.  *
  21.  *    @(#)globals.h    6.0 (Berkeley) 92/06/15
  22.  */
  23.  
  24. #include <stdio.h>
  25. #include <memory.h>             /* gst: 24 mar 89 */
  26.  
  27. #ifdef __IBMC__              /* IBM C Set/2 and other IBM C compilers */
  28. # ifdef __OS2__
  29. #  ifndef OS2
  30. #   define OS2
  31. #  endif
  32. # endif
  33. #endif
  34.  
  35. #ifdef MSDOS        
  36. # ifndef OS2
  37. #  define OS2
  38. # endif
  39. #endif
  40.  
  41. #ifdef OS2
  42. # ifndef ANSIC
  43. #  define ANSIC
  44. # endif
  45. #endif
  46.  
  47. #define BACKSLASH '\\'
  48. #define bufsize 1000            /* size of internal buffers */
  49. #define inp_bufs 1000           /* size of input buffer */
  50. #define sc_size 5000            /* size of save_com buffer */
  51. #define label_offset 2          /* number of levels a label is placed to left
  52.                                    of code */
  53. #define cplus_ppp_indent 2      /* spaces to indent public, private, protected
  54.                                    in c++ */
  55.  
  56. #define false 0
  57. #define true  1
  58.  
  59.  
  60. FILE *input;                    /* the fid for the input file */
  61. FILE *output;                   /* the output file */
  62.  
  63. #ifdef OS2
  64. #define check_size(name) \
  65.     if (e_##name >= l_##name) { \
  66.         register nsize = l_##name-s_##name+400; \
  67.         name##buf = (char *) realloc(name##buf, nsize); \
  68.         e_##name = name##buf + (e_##name-s_##name) + 1; \
  69.         l_##name = name##buf + nsize - 5; \
  70.         s_##name = name##buf + 1; \
  71.     }
  72. #else
  73. #define check_size(name) \
  74.     if (e_/**/name >= l_/**/name) { \
  75.         register nsize = l_/**/name-s_/**/name+400; \
  76.         name/**/buf = (char *) realloc(name/**/buf, nsize); \
  77.         e_/**/name = name/**/buf + (e_/**/name-s_/**/name) + 1; \
  78.         l_/**/name = name/**/buf + nsize - 5; \
  79.         s_/**/name = name/**/buf + 1; \
  80.     }
  81. #endif
  82.  
  83. char *labbuf;                   /* buffer for label */
  84. char *s_lab;                    /* start ... */
  85. char *e_lab;                    /* .. and end of stored label */
  86. char *l_lab;                    /* limit of label buffer */
  87.  
  88. char *codebuf;                  /* buffer for code section */
  89. char *s_code;                   /* start ... */
  90. char *e_code;                   /* .. and end of stored code */
  91. char *l_code;                   /* limit of code section */
  92.  
  93. char *combuf;                   /* buffer for comments */
  94. char *s_com;                    /* start ... */
  95. char *e_com;                    /* ... and end of stored comments */
  96. char *l_com;                    /* limit of comment buffer */
  97.  
  98. char in_buffer[inp_bufs];       /* input buffer */
  99. char *buf_ptr;                  /* ptr to next character to be taken from
  100.                                    in_buffer */
  101. char *buf_end;                  /* ptr to first after last char in in_buffer */
  102.  
  103. char save_com[sc_size];         /* input text is saved here when looking for
  104.                                    the brace after an if, while, etc */
  105. char *sc_end;                   /* pointer into save_com buffer */
  106.  
  107. char *bp_save;                  /* saved value of buf_ptr when taking input
  108.                                    from save_com */
  109. char *be_save;                  /* similarly saved value of buf_end */
  110.  
  111. char token[bufsize];            /* the last token scanned */
  112.  
  113. int cplus;                      /* c++ */
  114. int pointer_as_binop;
  115. int blanklines_after_declarations;
  116. int blanklines_before_blockcomments;
  117. int blanklines_after_procs;
  118. int blanklines_around_conditional_compilation;
  119. int swallow_optional_blanklines;
  120. int n_real_blanklines;
  121. int prefix_blankline_requested;
  122. int postfix_blankline_requested;
  123.  
  124. int tabsize;
  125.  
  126. int break_comma;                /* when true and not in parens, break after a
  127.                                    comma */
  128. int btype_2;                    /* when true, brace should be on same line as
  129.                                    if, while, etc */
  130. int btype_3;                    /* when true, braces are not only on the next
  131.                                    line but indented with the enclosed code */
  132. float case_ind;                 /* indentation level to be used for a "case n:" */
  133. int code_lines;                 /* count of lines with code */
  134. int had_eof;                    /* set to true when input is exhausted */
  135. int line_no;                    /* the current line number. */
  136. int max_col;                    /* the maximum allowable line length */
  137. int verbose;                    /* when true, non-essential error messages are
  138.                                    printed */
  139. int cuddle_else;                /* true if else should cuddle up to '}' */
  140. int star_comment_cont;          /* true iff comment continuation lines should
  141.                                    have stars at the beginning of each line. */
  142. int comment_delimiter_on_blankline;
  143. int troff;                      /* true iff were generating troff input */
  144. int procnames_start_line;       /* if true, the names of procedures being
  145.                                    defined get placed in column 1 (ie. a
  146.                                    newline is placed between the type of the
  147.                                    procedure and its name) */
  148. int proc_calls_space;           /* If true, procedure calls look like: foo(bar)
  149.                                    rather than foo (bar) */
  150. int parens_space;               /* If true, parens gets spaces inside them */
  151. int format_col1_comments;       /* If comments which start in column 1 are to
  152.                                    be magically reformatted (just like comments
  153.                                    that begin in later columns) */
  154. int inhibit_formatting;         /* true if INDENT OFF is in effect */
  155. int suppress_blanklines;        /* set iff following blanklines should be
  156.                                    suppressed */
  157. int continuation_indent;        /* set to the indentation between the edge of
  158.                                    code and continuation lines */
  159. int lineup_to_parens;           /* if true, continued code within parens will
  160.                                    be lined up to the open paren */
  161. int Bill_Shannon;               /* true iff a blank should always be inserted
  162.                                    after sizeof */
  163. int blanklines_after_declarations_at_proctop; /* This is vaguely similar to
  164.                                                  blanklines_after_declarations
  165.                                                  except that it only applies to
  166.                                                  the first set of declarations
  167.                                                  in a procedure (just after the
  168.                                                  first '{') and it causes a
  169.                                                  blank line to be generated
  170.                                                  even if there are no
  171.                                                  declarations */
  172. int block_comment_max_col;
  173. int extra_expression_indent;    /* True if continuation lines from the
  174.                                    expression part of "if(e)", "while(e)",
  175.                                    "for(e;e;e)" should be indented an extra tab
  176.                                    stop so that they don't conflict with the
  177.                                    code that follows */
  178.  
  179. /* -troff font state information */
  180.  
  181. struct fstate
  182. {
  183.     char font[4];
  184.     char size;
  185.     int allcaps:1;
  186. };
  187. char *chfont();
  188.  
  189. struct fstate
  190.     keywordf,                   /* keyword font */
  191.     stringf,                    /* string font */
  192.     boxcomf,                    /* Box comment font */
  193.     blkcomf,                    /* Block comment font */
  194.     scomf,                      /* Same line comment font */
  195.     bodyf;                      /* major body font */
  196.  
  197.  
  198. #define STACKSIZE 150
  199.  
  200. struct parser_state
  201. {
  202.     int last_token;
  203.     struct fstate cfont;        /* Current font */
  204.     int p_stack[STACKSIZE];     /* this is the parsers stack */
  205.     int il[STACKSIZE];          /* this stack stores indentation levels */
  206.     float cstk[STACKSIZE];      /* used to store case stmt indentation levels */
  207.     int box_com;                /* set to true when we are in a "boxed"
  208.                                    comment. In that case, the first non-blank
  209.                                    char should be lined up with the / in /* */
  210.     int comment_delta, n_comment_delta;
  211.     int cast_mask;              /* indicates which close parens close off casts */
  212.     int sizeof_mask;            /* indicates which close parens close off
  213.                                    sizeof''s */
  214.     int block_init;             /* true iff inside a block initialization */
  215.     int block_init_level;       /* The level of brace nesting in an
  216.                                    initialization */
  217.     int last_nl;                /* this is true if the last thing scanned was a
  218.                                    newline */
  219.     int in_or_st;               /* Will be true iff there has been a declarator
  220.                                    (e.g. int or char) and no left paren since
  221.                                    the last semicolon. When true, a '{' is
  222.                                    starting a structure definition or an
  223.                                    initialization list */
  224.     int bl_line;                /* set to 1 by dump_line if the line is blank */
  225.     int col_1;                  /* set to true if the last token started in
  226.                                    column 1 */
  227.     int com_col;                /* this is the column in which the current
  228.                                    coment should start */
  229.     int com_ind;                /* the column in which comments to the right of
  230.                                    code should start */
  231.     int com_lines;              /* the number of lines with comments, set by
  232.                                    dump_line */
  233.     int dec_nest;               /* current nesting level for structure or init */
  234.     int decl_com_ind;           /* the column in which comments after
  235.                                    declarations should be put */
  236.     int decl_on_line;           /* set to true if this line of code has part of
  237.                                    a declaration on it */
  238.     int i_l_follow;             /* the level to which ind_level should be set
  239.                                    after the current line is printed */
  240.     int in_decl;                /* set to true when we are in a declaration
  241.                                    stmt.  The processing of braces is then
  242.                                    slightly different */
  243.     int in_stmt;                /* set to 1 while in a stmt */
  244.     int ind_level;              /* the current indentation level */
  245.     int ind_size;               /* the size of one indentation level */
  246.     int ind_stmt;               /* set to 1 if next line should have an extra
  247.                                    indentation level because we are in the
  248.                                    middle of a stmt */
  249.     int last_u_d;               /* set to true after scanning a token which
  250.                                    forces a following operator to be unary */
  251.     int leave_comma;            /* if true, never break declarations after
  252.                                    commas */
  253.     int ljust_decl;             /* true if declarations should be left
  254.                                    justified */
  255.     int out_coms;               /* the number of comments processed, set by
  256.                                    pr_comment */
  257.     int out_lines;              /* the number of lines written, set by
  258.                                    dump_line */
  259.     int p_l_follow;             /* used to remember how to indent following
  260.                                    statement */
  261.     int paren_level;            /* parenthesization level. used to indent
  262.                                    within stmts */
  263.     short paren_indents[20];    /* column positions of each paren */
  264.     int pcase;                  /* set to 1 if the current line label is a
  265.                                    case.  It is printed differently from a
  266.                                    regular label */
  267.     int search_brace;           /* set to true by parse when it is necessary to
  268.                                    buffer up all info up to the start of a stmt
  269.                                    after an if, while, etc */
  270.     int unindent_displace;      /* comments not to the right of code will be
  271.                                    placed this many indentation levels to the
  272.                                    left of code */
  273.     int use_ff;                 /* set to one if the current line should be
  274.                                    terminated with a form feed */
  275.     int want_blank;             /* set to true when the following token should
  276.                                    be prefixed by a blank. (Said prefixing is
  277.                                    ignored in some cases.) */
  278.     int else_if;                /* True iff else if pairs should be handled
  279.                                    specially */
  280.     int decl_indent;            /* column to indent declared identifiers to */
  281.     int its_a_keyword;
  282.     int sizeof_keyword;
  283.     int dumped_decl_indent;
  284.     float case_indent;          /* The distance to indent case labels from the
  285.                                    switch statement */
  286.     float case_code_indent;     /* The distance to indent case code from the
  287.                                    case label */
  288.     int in_parameter_declaration;
  289.     int indent_parameters;
  290.     int tos;                    /* pointer to top of stack */
  291.     char procname[100];         /* The name of the current procedure */
  292.     int just_saw_decl;
  293.     int cc_comment;             /* saw a C++ comment ("//...") */
  294. }   ps;
  295.  
  296. int ifdef_level;
  297. struct parser_state state_stack[5];
  298. struct parser_state match_state[5];
  299.  
  300. typedef enum cplus_flag
  301. {
  302.     c_only,
  303.     c_and_cplus,
  304.     cplus_only
  305. }   cplus_flag;
  306.  
  307. #ifdef ANSIC
  308. #include "proto.h"
  309. #endif
  310.